package com.qingshu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingshu.common.entity.custom.Singer;
import com.qingshu.common.util.model.FieldUtil;
import com.qingshu.mapper.SingerMapper;
import com.qingshu.service.ISingerService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Huzz
 * @since 2021-12-09
 */
@Service
public class SingerServiceImpl extends ServiceImpl<SingerMapper, Singer> implements ISingerService {

    @Override
    public boolean addSinger(Singer model) {
        // 设置创建信息, 默认信息默认也是更新信息
        FieldUtil.setCreatedAndUpdateField(model);

        return this.baseMapper.insert(model) > 0;
    }

    @Override
    public Singer findSingerById(Integer singerId) {
        return this.baseMapper.selectById(singerId);
    }

    @Override
    public List<Singer> findSingerByName(String name) {
        LambdaQueryWrapper<Singer> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Singer::getSingerName, name);
        return this.baseMapper.selectList(wrapper);
    }
}
